<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/base/jsp/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<%@ include file="/base/jsp/jscss.jsp"%>
	<title></title>
	<script type="text/javascript">
	
		$(function () {
			$('#dataList').datagrid({  
				
				url:'${ctx }/base/security/user/user!list_json.do',
			    title:'list',
			    pagination:true,
			    rownumbers:true,
// 			    singleSelect:true, //单选
			    fitColumns: true,
			    striped: true,
			    idField:'id',
			    toolbar:easyUi.initButton([{name:'add'},{name:'edit',text:'设置角色',handler:'settingRole'}]),
			    frozenColumns:[[
				                {field:'ss',checkbox:true,title:'Code',},
// 				                {field:'id',title:'角色',},
							]],
			    columns:[[  
			            {field:'id',title:'编号',width:100},  
		                {field:'username',title:'名称',width:100},  
		            ]],
			});
		});
		
		function settingRole () {
			
			var roleUrl = "${ctx}/base/security/role/role!list_json.do";
			
			$.post(roleUrl,function(data){
				$.each(data.result,function (i){
					var obj = data.result[i];
					var id = obj.id;
					var name = obj.name;
					$("#roleSelect").html("");
					$("#roleSelect").append($("<label>").append($("<input>",{type:'checkbox', val:id}).after(name)));
				});
				
				easyUi.initButtonBar("toolbar",[{name:'save',handler:'saveSettingRole'}]);
				easyUi.defaultWindow("centert",'设置角色');
				
			});
		}
		
		function saveSettingRole() {
			alert(easyUi.datagridGetSelected("dataList").id);
			$("#form_settingRole").attr("src","${ctx}/base/security/user/user!saveSettingRole.do");
			$("#userid").val(easyUi.datagridGetSelected("dataList").id);
			$("#form_settingRole").submit();
		}
		function add() {
			easyUi.defaultWindow('addBean_panel');
		}
	</script>
</head>
<body>
<!-- <input type="checkbox"> -->
<div id="dataList"></div>

<hr/>
<!-- 添加一个用户 -->
<div id='addBean_panel' style="display: none;">
	<div id="formToolBar" class="datagrid-toolbar"></div>
	<form id="form" method="post" action="${ctx }/base/security/user/user!save.do">
		<table>
			<tr>
				<td>username:</td>
				<td><input class="easyui-validatebox" type="text" name="bean.username" data-options="required:true"></input></td>
				<td>userBase.name:</td>
				<td><input class="easyui-validatebox" type="text" name="bean.userBase.name" data-options="required:true"></input></td>
			</tr>
			<tr>
				<td><input type="submit"/></td>
			</tr>
		</table>
	</form>
</div>

<!-- 用户设置角色 -->
<div id='centert'>
	<div id="toolbar" class="datagrid-toolbar"></div>
	<form id="form_settingRole" method="post">
		<input name="userid" id="userid"/>
		<table>
			<tr>
				<td>role:</td>
				<td><div id="roleSelect"></div></td>
			</tr>
		</table>
	</form>
</div>


</body>
</html>